import * as types from '../constants/ActionTypes';
import Request from '../utils/request';

/*
*我的业绩
*/
const fetchPerfence = (isLoading, rank, oday, oweek, omonth, flag) => (dispatch) => {
  dispatch(receivePerfenceLoading(isLoading));
  let URL = '';
  if (flag === 1) {
    URL = `/dealer/saleperformance?rank=${rank}`;
  } else {
    URL = `/dealer/saleperformance?rank=${rank}&&oday=${oday}&&oweek=${oweek}&&omonth=${omonth}`;
  }
  Request.get({
    url: URL,
    success: (data) => {
      dispatch(receivePerfence(data));
    },
    fail: () => {
      dispatch(receivePerfence({}));
    },
    error: () => {
      dispatch(receivePerfence({}));
    },
  });
};

const receivePerfence = perfenceData => ({
  type: types.PERFENCE,
  perfenceData,
});

const receivePerfenceLoading = perfenceIsLoading => ({
  type: types.PERFENCE_LOADING,
  perfenceIsLoading,
});
export default fetchPerfence;
